#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<string.h>

extern char **environ;
/// main有参数吗?有
/////// 最多可以有几个? 3个
/////// 是父进程传递给我们的

int main(int argc, char* argv[])
{
    //打印环境变量

    //法三 减掉env,创建environ二级指针 减去-std=c99
    (void)argc;
    (void)argv;
    if(fork() == 0)
    {
        for(int i = 0; environ[i]; i++)
        {
            printf("environ[%d]-> %s\n", i, argv[i]);
        }
    }
    sleep(3);



    //法二pro
    //(void)argc;
    //(void)argv;
    //(void)env;
    //const char *who = getenv("USER");

    //if(who == NULL) return 1;
    //
    //if(strcmp(who, "LY") == 0)
    //{
    //    printf("这是正常的程序执行逻辑\n");
    //}
    //else
    //{
    //    printf("Only LY!\n");
    //}
    
    

    





    //法二
    //(void)argc;
    //(void)argv;
    //(void)env;
    //char *value = getenv("PATH");
    //if(value == NULL)return 1;

    //printf("PATH:%s\n", value);


    ////法一
    //(void)argv;
    //(void)argc;
    //for(int i = 0; env[i]; i++)
    //{
    //    printf("env[%d]->:%s\n", i, env[i]);
    //}

    return 0;
}
















